﻿using System;
using System.Collections.Generic;

namespace ComTools.EnumHelper
{
    /// <summary>
    /// 枚举项
    /// </summary>
    public class EnumItem
    {
        public EnumItem(string text, string value)
        {
            this.Text = text;
            this.Value = value;
        }

        public override string ToString()
        {
            return "<option value='" + this.Value + "'>" + this.Text + "</option>";
        }

        public EnumItem() { }

        public string Value { get; set; }

        public string Text { get; set; }


        /// <summary>
        /// 将枚举转换成list
        /// </summary>
        /// <param name="type"></param>
        /// <param name="isAddAll"></param>
        /// <returns></returns>
        public static List<EnumItem> GetEnumList(Type type, bool isAddAll)
        {
            List<EnumItem> list = new List<EnumItem>();
            if (isAddAll)
            {
                list.Add(new EnumItem("--", "-1"));
            }
            String[] EnumFuncTitle = System.Enum.GetNames(type);
            Int32 intCnt = 0;
            foreach (Int32 intValue in System.Enum.GetValues(type))
            {
                list.Add(new EnumItem(EnumFuncTitle[intCnt], intValue.ToString()));
                intCnt += 1;
            }
            return list;
        }
    }
}
